import { IMG_PATH } from '../../../config/index.js'
import { ApiRootUrl } from '../../../config/index.js'
import Toast from '../../../@vant/weapp/toast/toast';
import Dialog from '../../../@vant/weapp/dialog/dialog';
// pages/company/cloudPatrol/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height:0,
    active:0,
    pageNumber:1,
    pageSize:10,
    tabList:[{
      value:'未完成',
    },{
      value:'已完成'
    }],
    dataList:[
    ]
  },
  //切换首页标签
  onChange(value){
    let self=this
    this.setData({
      active:value.detail.index
    })
    console.log(value.detail.index)
    self.queryTaskByCondition()
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let query = wx.createSelectorQuery();
    query.select('.nav-style').boundingClientRect(rect => {
      let height = rect.height;
      // let statusBarHeight=wx.getSystemInfoSync()['statusBarHeight'],
      this.setData({
        height: wx.getSystemInfoSync().windowHeight - height,
      })
    }).exec();
    
  },
  loadMore(){
    let self = this;
    console.log('触底');
    if(self.data.dataList.length<self.data.total){
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    
    self.setData({
      pageNumber:self.data.pageNumber*1+1
    },()=>{

    
    let params={
      pageSize:10,
      pageNumber:self.data.pageNumber,
      status:self.data.active,
    }
    wx.request({
      url: `${ApiRootUrl}/cloudCheckTask/queryTaskByCondition`,
      method: 'POST',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      success(res) {
        Toast.clear()
        if (res.data.code == 20000) {
          console.log(res.data.data);
          let data=res.data.data.list
          var newArr = self.data.dataList.concat(data)
          self.setData({
            dataList:newArr
          })
        } else {
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res) {
        Toast.clear()
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络错误',
        });
      }
    })
  })
}
  },
  // 获取云端巡查列表
  queryTaskByCondition(){
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    let self = this;
    let params = {
      status:self.data.active,
      pageNumber:self.data.pageNumber,
      pageSize:self.data.pageSize
    }
    wx.request({
      url: `${ApiRootUrl}/cloudCheckTask/queryTaskByCondition`,
      method: 'post',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      params:params,
      success(res) {
        Toast.clear();
        if(res.data.code == 20000){
          console.log(res);
          self.setData({
            dataList:res.data.data.list,
            total:res.data.data.total
          })
        }else{
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  toOtherPage(e){
    console.log(e);

    let type = e.currentTarget.dataset.type
    let orgCode = e.currentTarget.dataset.orgcode
    let processCode = e.currentTarget.dataset.processcode
    let active=this.data.active
    // console.log(processCode,orgCode);
    // return

   
      if(type == 2){
        wx.navigateTo({
          url: `../cloudPatrol/updateDetaily/index?orgCode=${orgCode}&processCode=${processCode}&active=${active}`,
        })
      }else if(type == 0) {
        wx.navigateTo({
          url: `../cloudPatrol/task/index?orgCode=${orgCode}&processCode=${processCode}&active=${active}`,
        })
      }else if(type == 1){
        wx.navigateTo({
          url: `../cloudPatrol/AntiFraud/index?orgCode=${orgCode}&processCode=${processCode}&active=${active}`,
        })
      }else if(type == 3){
        wx.navigateTo({
          url: `../cloudPatrol/AbnormalLanding/index?orgCode=${orgCode}&processCode=${processCode}&active=${active}`,
        })
      }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.queryTaskByCondition()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})